package com.huixh.train.business.consumer;

import com.huixh.train.business.constant.RabbitMqConstant;
import com.huixh.train.business.dto.ConfirmOrderMqDto;
import com.huixh.train.business.service.ConfirmOrderService;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @author huixh
 */
@Component
public class ConfirmOrderConsumer {
    private static final Logger logger = LoggerFactory.getLogger(ConfirmOrderConsumer.class);
    @Resource
    private ConfirmOrderService confirmOrderService;
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "queue1", durable = "true"),
            exchange = @Exchange(value = RabbitMqConstant.CONFIRM_ORDER, type = ExchangeTypes.FANOUT)
    ))
    public void onConfirm(ConfirmOrderMqDto req) {
        logger.info("消费者收到订单消息【{}】",req);
        confirmOrderService.doConfirm(req);
    }
}
